<%--
  Created by IntelliJ IDEA.
  User: LMY
  Date: 2025/6/21
  Time: 20:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>域对象的使用</title>
    </head>

    <body>
        <%
            //在不同的域对象中放入数据
            pageContext.setAttribute("k1", "pageContext数据(k1)");
            request.setAttribute("k1", "request数据(k1)");
            session.setAttribute("k1", "session数据(k1)");
            application.setAttribute("k1", "application数据(k1)");

            //请求转发操作
//            request.getRequestDispatcher("/scope2.jsp").forward(request, response);

            //重定向操作
            String contextPath = request.getContextPath();// 返回的就是工程路径 /jsp
//            response.sendRedirect("/jsp/scope2.jsp");
            response.sendRedirect(contextPath + "/scope2.jsp");
        %>
        <h1>四个域对象在本页面获取的情况</h1>
        pageContext-k1: <%=pageContext.getAttribute("k1")%><br/>
        request-k1: <%=request.getAttribute("k1")%><br/>
        session-k1: <%=session.getAttribute("k1")%><br/>
        application-k1: <%=application.getAttribute("k1")%>
    </body>
</html>
